﻿using System;
using System.Collections.Generic;

using System.Text;

namespace WeFeTeLib
{
    abstract public class Framework
    {
        /// <summary>
        /// The list of the result (Temporal until I found the best way to show the results)
        /// </summary>
        internal List<Result> debugResults = new List<Result>();

        internal int totalMatch = 0;
        internal int currentMatch = 0;
        internal string name;
        internal int totalTests = 0;

        internal List<File> frameworkFiles = new List<File>();
        internal List<Cookie> frameworkCookies = new List<Cookie>();
        internal List<Folder> frameworkFolders = new List<Folder>();
        internal List<Header> frameworkHeaders = new List<Header>();

        public Framework()
        {
            setDefaultFiles();
            setDefaultCookies();
            setDefaultFolders();
            setDefaultHeaders();

            totalMatch = ((frameworkFiles.Count) 
                + (frameworkCookies.Count * 2) 
                + (frameworkFolders.Count)
                + (frameworkHeaders.Count));

            totalTests = (frameworkCookies.Count + 
                frameworkFiles.Count + frameworkFolders.Count + frameworkHeaders.Count);
        }

        /// <summary>
        /// The Handler of the File testing
        /// </summary>
        /// <param name="o">The Framework object</param>
        /// <param name="e">The FileEventArgs with the File object and conditions matched</param>
        internal delegate void FileHandler(object o, FileEventArgs e);

        /// <summary>
        /// Get the File objects to test
        /// </summary>
        /// <returns>Returns a List<![CDATA[<File>]]> of the files to test</returns>
        public abstract void setDefaultFiles();
        public List<File> getDefaultFiles()
        {
            return frameworkFiles;
        }

        internal delegate void CookieHandler(object o, CookieEventArgs e);
        public  abstract void setDefaultCookies();
        public List<Cookie> getDefaultCookies()
        {
            return frameworkCookies;
        }

        internal delegate void FolderHandler(object o, FolderEventArgs e);
        public abstract void setDefaultFolders();
        public List<Folder> getDefaultFolders()
        {
            return frameworkFolders;
        }

        internal delegate void HeaderHandler(object o, HeaderEventArgs e);
        public abstract void setDefaultHeaders();
        public List<Header> getDefaultHeaders()
        {
            return frameworkHeaders;
        }


        /// <summary>
        /// Returns a List<![CDATA[<string>]]> of the result of the test
        /// </summary>
        /// <returns></returns>
        public List<Result> getDebugResults()
        {
            return debugResults;
        }

        /// <summary>
        /// Add a result to the list of the test.
        /// </summary>
        /// <param name="Result"></param>
        public void addDebugResult(string File, string Type, int Conditions)
        {
            debugResults.Add(new Result(File, Type, Conditions));
        }

        public int getAccuracy()
        {
            int percent = 0;

            foreach (Result r in debugResults)
            {
                currentMatch += r.Conditions;
            }

            percent = (currentMatch * 100) / totalMatch;            

            return percent;
        }

        public string Name
        {
            get { return name; }
        }
    }
}
